package com.hxzy.projectssmplus.controller;

import com.hxzy.projectssmplus.dto.HousePlanningDTO;
import com.hxzy.projectssmplus.entity.HouseNew;
import com.hxzy.projectssmplus.entity.HousePlanning;
import com.hxzy.projectssmplus.service.HouseNewService;
import com.hxzy.projectssmplus.service.HousePlanningService;
import com.hxzy.projectssmplus.vo.AjaxResult;
import com.hxzy.projectssmplus.vo.HousePlanningVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class HousePlanningController extends BaseController {
    @Autowired
    private HousePlanningService housePlanningService;

    @Autowired
    private HouseNewService houseNewService;

    @GetMapping(value = "/planning/data")
    public AjaxResult planningData(HousePlanningDTO housePlanningDTO){
        List<HousePlanningVo> housePlannings = this.housePlanningService.seatchByXML(housePlanningDTO);


        return AjaxResult.success_data(housePlannings);
    }
    @GetMapping(value = "/planning/del")
    public AjaxResult planningDel(Long houseId){
        Integer integer1 = this.housePlanningService.deleteByHouseId(houseId);
        return integer1>0?AjaxResult.success("planning/del删除成功"):AjaxResult.error("/planning.del删除失败");
    }
    @PostMapping(value = "/planning/add")
    public AjaxResult planningAdd(@RequestBody HousePlanning housePlanning){
        Integer integer = this.housePlanningService.planningAdd(housePlanning);
        return integer>0?AjaxResult.success("planning/add新增成功"):AjaxResult.error("planning/add新增失败");
    }
    @PostMapping(value = "/planning/update")
    public AjaxResult planningUpdate(@RequestBody HousePlanning housePlanning){
        Integer integer = this.housePlanningService.planningUpdate(housePlanning);
        return integer>0?AjaxResult.success("planning/update修改成功"):AjaxResult.error("planning/update修改失败");
    }

    @GetMapping(value = "/planning/one/{houseId}")
    public AjaxResult panningOne(@PathVariable(value = "houseId") Long houseId){
        HousePlanning housePlanning = this.housePlanningService.planningOne(houseId);
        if (housePlanning==null){
             housePlanning = new HousePlanning();
        }
        return AjaxResult.success_data(housePlanning);
    }


}
